package com.example.store.service.impl;

import com.example.store.entity.Product;
import com.example.store.mapper.ProductMapper;
import com.example.store.service.IProductService;
import com.example.store.service.ex.ProductNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public List<Product> findHotList() {
        List<Product> hotList = productMapper.findHotList();
        for (Product product : hotList){
            product.setPriority(null);
            product.setCreatedUser(null);
            product.setCreatedTime(null);
            product.setModifiedUser(null);
            product.setModifiedTime(null);
        }
        return hotList;
    }

    @Override
    public Product findById(Integer id) {

        Product product = productMapper.findById(id);
        if (product != null){
            product.setPriority(null);
            product.setCreatedUser(null);
            product.setCreatedTime(null);
            product.setModifiedUser(null);
            product.setModifiedTime(null);
        }else {
            throw new ProductNotFoundException("尝试访问的商品不存在");
        }

        return product;
    }

    @Override
    public List<Product> findALl() {
        return null;
    }
}
